﻿using Microsoft.Extensions.Configuration;
using PoemGame.Domain.GameAggregate;

namespace PoemGame.Domain.Services.Factory.WebApi
{
    public class CheckAnswerServiceFactory : IDomainServiceFactory<ICheckAnswerService>
    {
        private readonly IConfiguration _configuration;
        private readonly IHttpClientFactory httpClientFactory;

        public CheckAnswerServiceFactory(IConfiguration configuration, IHttpClientFactory httpClientFactory)
        {
            _configuration = configuration;
            this.httpClientFactory = httpClientFactory;
        }

        public ICheckAnswerService GetService(GameType gamePlayType)
        {
            var remoteurl = _configuration["CheckAnswerServices:"
                                           + gamePlayType.MainType + "_" + gamePlayType.SubType];
            var httpClient = this.httpClientFactory.CreateClient();
            httpClient.Timeout = new TimeSpan(0, 0, 30);
           return new CheckAnswerServiceRemote(httpClient,remoteurl);
            ;
        }
    }
}